import {
	defineStore
} from 'pinia'
import {
	getReadListAndStatus,
	getDepartmentMsgList,
} from '@/api/dep_msg.js'
import { useUserInfoStore } from '@/store/userInfo.js'

const userStore = useUserInfoStore()
export const useMsg = defineStore('messageinfor', {
	state: () => {
		return {
			read_list: [],
			msg_list:[]
		}
	},
	actions: {
		async returnReadList(id) {
			this.read_list = []
			this.msg_list = []
			const res = await getReadListAndStatus(id)
			if(res.data[0].read_list){
				this.read_list = JSON.parse(res.data[0].read_list)
			}else{
				this.read_list = []
			}
			const res1 = await getDepartmentMsgList(userStore.department)
			this.msg_list = res1.data
		}
	},
	persist:true
})